package com.cpe.service.sharing;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.cpe.data.domain.sharing.Sharing;
import com.cpe.data.domain.sharing.SharingImage;
import com.cpe.repository.mapper.sharing.SharingImageMapper;
import com.cpe.repository.mapper.sharing.SharingMapper;

@Service
public class SharingService {

	@Resource
	private SharingMapper sharingMapper;

	@Resource
	private SharingImageMapper sharingImageMapper;

	/**
	 * 发表一条动态
	 */
	@Transactional
	public void add(Sharing sharing) {
		Assert.notNull(sharing);
		Assert.hasText(sharing.getMemberId());
		Assert.hasText(sharing.getNickName());
		Assert.hasText(sharing.getContent());
		Assert.hasText(sharing.getImageUrl());
		sharing.setCreateTime(new Date());
		sharingMapper.insert(sharing);
		SharingImage sharingImage = new SharingImage();
		sharingImage.setSharingId(sharing.getId());
		sharingImage.setImageUrl(sharing.getImageUrl());
		sharingImageMapper.insert(sharingImage);
	}
}
